package org.dtrd.config.wechat.entity.request.wechatpay;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * 微信预下单请求
 *
 * @author xiao
 */
@Data
public class PrePayRequest {
    /**
     * 订单金额信息（必填）
     */
    private OrderAmount amount;
    /**
     * 商户号（必填）
     */
    private String mchid;
    /**
     * 商户订单号（必填）
     */
    private String out_trade_no;
    /**
     * 应用ID（必填）
     */
    private String appid;
    /**
     * 商品描述（必填）
     */
    private String description;
    /**
     * 微信支付回调地址，必须为直接可访问的URL，不允许携带查询串，要求必须为https地址
     */
    private String notify_url;
    /**
     * 场景信息-支付场景描述（H5支付时必填）
     */
    private SceneInfo scene_info;

    /**
     * 支付者信息
     * 小程序端 必填
     */
    private Payer payer;

    // ============================ 非必填项 =========================================

    /**
     * 交易结束时间
     * 订单失效时间是针对订单号而言的，由于在请求支付的时候有一个必传参数prepay_id只有两小时的有效期，所以在重入时间超过2小时的时候需要重新请求下单接口获取新的prepay_id
     * 格式：yyyy-MM-DDTHH:mm:ss+TIMEZONE
     * 示例值：2018-06-08T10:34:56+08:00
     */
    @JsonProperty("time_expire")
    private String timeExpire;

    /**
     * 附加信息，查询API和支付通知原样返回
     */
    private String attach;

    /**
     * 订单优惠标记
     */
    @JsonProperty("goods_tag")
    private String goodsTag;

    /**
     * 优惠功能
     */
    private String detail;

    /**
     * 结算信息
     */
    @JsonProperty("settle_info")
    private String settleInfo;


    public static final class PrePayRequestBuilder {
        private OrderAmount amount;
        private String mchid;
        private String outTradeNo;
        private String appid;
        private String description;
        private String notifyUrl;
        private SceneInfo scene_info;
        private String timeExpire;
        private String attach;
        private String goodsTag;
        private String detail;
        private String settleInfo;

        private PrePayRequestBuilder() {
        }

        public static PrePayRequestBuilder getInstance() {
            return new PrePayRequestBuilder();
        }

        public PrePayRequestBuilder withAmount(OrderAmount amount) {
            this.amount = amount;
            return this;
        }

        public PrePayRequestBuilder withAmount(int total) {
            this.amount = new OrderAmount(total);
            return this;
        }

        public PrePayRequestBuilder withMchid(String mchid) {
            this.mchid = mchid;
            return this;
        }

        public PrePayRequestBuilder withOutTradeNo(String outTradeNo) {
            this.outTradeNo = outTradeNo;
            return this;
        }

        public PrePayRequestBuilder withAppid(String appid) {
            this.appid = appid;
            return this;
        }

        public PrePayRequestBuilder withDescription(String description) {
            this.description = description;
            return this;
        }

        public PrePayRequestBuilder withNotifyUrl(String notifyUrl) {
            this.notifyUrl = notifyUrl;
            return this;
        }

        public PrePayRequestBuilder withScene_info(SceneInfo scene_info) {
            this.scene_info = scene_info;
            return this;
        }

        public PrePayRequestBuilder withTimeExpire(String timeExpire) {
            this.timeExpire = timeExpire;
            return this;
        }

        public PrePayRequestBuilder withAttach(String attach) {
            this.attach = attach;
            return this;
        }

        public PrePayRequestBuilder withGoodsTag(String goodsTag) {
            this.goodsTag = goodsTag;
            return this;
        }

        public PrePayRequestBuilder withDetail(String detail) {
            this.detail = detail;
            return this;
        }

        public PrePayRequestBuilder withSettleInfo(String settleInfo) {
            this.settleInfo = settleInfo;
            return this;
        }

        public PrePayRequest build() {
            PrePayRequest prePayRequest = new PrePayRequest();
            prePayRequest.setAmount(amount);
            prePayRequest.setMchid(mchid);
            prePayRequest.setOut_trade_no(outTradeNo);
            prePayRequest.setAppid(appid);
            prePayRequest.setDescription(description);
            prePayRequest.setNotify_url(notifyUrl);
            prePayRequest.setScene_info(scene_info);
            prePayRequest.setTimeExpire(timeExpire);
            prePayRequest.setAttach(attach);
            prePayRequest.setGoodsTag(goodsTag);
            prePayRequest.setDetail(detail);
            prePayRequest.setSettleInfo(settleInfo);
            return prePayRequest;
        }
    }
}